package com.dem.javatestwebsocket.controller;

import com.dem.javatestwebsocket.service.impl.MessageRankService;
import com.dem.javatestwebsocket.vo.RestResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

@RestController
@RequestMapping("MessageRank")
public class MessageRankcontroller {
    @Autowired
    private MessageRankService messageRankService;

    // 增加用户消息计数
    @PostMapping("/increment/{userId}")
    public RestResultVo<String> incrementMessageCount(@PathVariable String userId) {
        messageRankService.incrementMessageCount(userId);
        return RestResultVo.ok("Message count incremented for user: " + userId);
    }

    // 获取Top10用户
    @GetMapping("/top10")
    public RestResultVo<Set<ZSetOperations.TypedTuple<String>>> getTopUsers() {
        Set<ZSetOperations.TypedTuple<String>> topUsers = messageRankService.getTop10();
        return RestResultVo.ok(topUsers);
    }

}
